package com.example.rtsp.config;

/**
 * @Author: 杜科璇
 * @Description: WebSocket配置
 * @Date: 2025/9/5 17:55
 * @Version: 1.0
 */
import com.example.rtsp.handler.VideoStreamHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private VideoStreamHandler videoStreamHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(videoStreamHandler, "/video-stream") // 添加处理器
                .setAllowedOrigins("*"); //允许所有来源的跨域请求
    }
}